﻿
@model IEnumerable<WebVideo.EntityFriend>
@{
    ViewBag.Title = "Danh sách bạn bè";
}

@{

    int cap1 = 0;
    int cap2 = 0;
    foreach (var item in Model)
    {
        if (item.LevelFriend == 1)
        {
            cap1 = cap1 + 1;

        }
        else if (item.LevelFriend == 2)
        {
            cap2 = cap2 + 1;
        }
    }
    }
    <div class="inner-container" id="inner-container" style="width: 8000px">
        <div class="wrap-widget">
            <div class="inner-widget _8">
                <h1>Danh sách bạn bè</h1>
                <div class="widget _2x3 phone bg-color-MediumSeaGreen">
                    <div class="widget-content">
                        @Html.Action("Index", "Individual", new { Friend = @ViewBag.DanhSachBanBe })
                    </div>
                    <!--/ .widget-content-->
                </div>
                <!--/ .widget-->
                <div class="widget _6x3 phone bg-color-white">
                    <div class="box-social-wrapper contScroll">
                        <div class="box-list-friend">
                            <h4><b>Bạn có @Model.ToList().Count bạn bè, @cap1 bạn cấp 1 và @cap2 bạn cấp 2  
                                @{if (ViewBag.DanhSachBanBe == Request.Cookies["UserId"].Value)
                                  {
                                       <input type="text" id="TimKiemFriend" placeholder="Nhập từ khóa để tìm kiếm...?" onkeypress="return TimKiemFriend(event)" />
                                  }
                                  }
                                </b></h4>
                                <div class="ListFriendSearch"> 
                                  
                                    @{      
                                        foreach (var item in Model)
                                        {
                                            <div class="friend-item">
                                                <div>       
                                                    @{if (item.UserName == Request.Cookies["UserId"].Value)
                                                      {

                                                          if (item.EntityUser.Avatar != null)
                                                          {               
                                                                <a href="@Url.Action("ThongTinCaNhan", "Individual", new { Friend = @item.UserNameFriend }, null)"><img src="/Content/Images/Avatar/@item.EntityUser.Avatar" /><p>@item.EntityUser.UserName</p></a>        
                                                          }
                                                          else
                                                          {
                                                                 <a href="@Url.Action("ThongTinCaNhan", "Individual", new { Friend = @item.UserNameFriend }, null)"><img src="@Url.Content("~/Content/Images/Avatar/AdminAvatar.jpg")" /><p>@item.EntityUser.UserName</p></a>        
                                                          }
                                                      }
                                                      else
                                                      {
                                                          if (item.EntityUser1.Avatar != null)
                                                          {               
                                                                <a href="@Url.Action("ThongTinCaNhan", "Individual", new { Friend = @item.UserName }, null)"><img src="/Content/Images/Avatar/@item.EntityUser1.Avatar" /><p>@item.EntityUser1.UserName</p></a>        
                                                          }
                                                          else
                                                          {
                                                                 <a href="@Url.Action("ThongTinCaNhan", "Individual", new { Friend = @item.UserName }, null)"><img src="@Url.Content("~/Content/Images/Avatar/AdminAvatar.jpg")" /><p>@item.EntityUser1.UserName</p></a>        
                                                          }
                                                      }
                                                     }                      
                                                </div>
                                            </div>
                                            <!--/ .friend-item-->
                                        }
                                }
                               </div>

                        </div>
                        <!--/ .box-list-friend-->
                    </div>
                    <!--/ .box-social-wrapper-->
                </div>
                <!--/ .widget-->
            </div>
            <!--/ .inner-widget-->
        </div>
        <!--/ .wrap-widget -->
    </div>
    <!--/ .inner-container-->

    @section occasionalScripts {
        <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/jquery.min.js")" ></script>
        <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/load.js")" ></script>
        <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/styles.js")" ></script>
        <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/jquery.nicescroll.min.js")" ></script>
    }
<script type="text/javascript">
    document.body.className = 'no-js';
    // thêm bạn
    $(document).ready(function () {
        $('li#TaiKhoanCuaBan').addClass('active');
    });
    function ThemFiend1(UserName) {
       
        var getURL = '@Url.Action("KetBan", "Individual")';
        var c = confirm('Bạn chắc chắn muốn kết bạn với người này?');
        if (c) {
            $.get(getURL, { "UserName": UserName }, function (data) {
                if (data != "Error") {
                    // $("a#" + UserName + "").attr("disabled", true);
                    $("a#" + UserName + "").hide();
                }
                else {
                    alert("Error");
                }
            });
        }
       
        return true;
    };
    // xóa bạn

    function XoaFriend1(UserName) {
        var getURL = '@Url.Action("XoaBan", "Individual")';
         var c = confirm('Bạn chắc chắn muốn hủy kết bạn với người này?');
         if (c) {
             $.get(getURL, { "UserName": UserName }, function (data) {
                 if (data != "Error") {
                     $("a#" + UserName + "").hide();
                 }
                 else {
                     alert("Error");
                 }
             });
         }

         return true;
    };

    function TimKiemFriend(e) {
        var key;
        if (window.event)
            key = window.event.keyCode;     //IE 
        else
            key = e.which;
       
            if (key == 13) {
            var search = $('#TimKiemFriend').val();
            if (search != "") {
                var getURL = '@Url.Action("TimKiemFiend", "Individual")';

                    $.get(getURL, { "search": search }, function (data) {
                        $("div.ListFriendSearch").html(data);
                    });
                }
                else {
                    window.location.href = "@Url.Action("DanhSachBanBe", "Individual",new { Friend = Request.Cookies["UserId"].Value }, null)";
                }
            }
        };
     
</script>
